package com.a214.yxz.yuejian013.Activity;

import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.a214.yxz.yuejian013.R;

import java.io.FileNotFoundException;

public class ShowSentActivity extends AppCompatActivity {
    private ImageButton return_btn, share_weixin, share_weibo, share_qq, pic_add;
    private ImageView pic1, pic2, pic3;
    private EditText picIntro;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_sent);

        return_btn = (ImageButton) findViewById(R.id.show_sent_return_btn);
        share_weixin = (ImageButton) findViewById(R.id.show_sent_syn_weixin);
        share_weibo = (ImageButton) findViewById(R.id.show_sent_syn_weibo);
        share_qq = (ImageButton) findViewById(R.id.show_sent_syn_qq);
        pic_add = (ImageButton) findViewById(R.id.show_sent_add);
        pic1 = (ImageView) findViewById(R.id.show_sent_pic1);
        pic2 = (ImageView) findViewById(R.id.show_sent_pic2);
        pic3 = (ImageView) findViewById(R.id.show_sent_pic3);
        picIntro = (EditText) findViewById(R.id.show_sent_picIntro);

        return_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        share_weixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        share_weibo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        share_qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        pic_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                intent.putExtra("return-data", true);
                startActivityForResult(intent, 1);

            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                Uri selectedImage=data.getData();
                String[] filePathColum = {MediaStore.Images.Media.DATA};
                Cursor cursor = this.getContentResolver().query(selectedImage,filePathColum,null,null,null);
                cursor.moveToFirst();
                int columnIndex = cursor.getColumnIndex(filePathColum[0]);
                String picturePath = cursor.getString(columnIndex);
                cursor.close();
                Uri uri = data.getData();
                ContentResolver cr = this.getContentResolver();
                try {
                    Bitmap bmp = BitmapFactory.decodeStream(cr.openInputStream(uri));
                    pic1.setImageBitmap(bmp);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                break;
        }
    }
}
